---
title: ServiceResponse
summary: API reference for ServiceResponse.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-08-21
library: SAIF.Application
reference_type: embedded
---

# ServiceResponse

`ServiceResponse` is the categorized message envelope returned by service-style managers built on [clsServiceAppManagerBase](clsServiceAppManagerBase.md). It starts optimistic (`Result = True`) and accumulates [ServiceMessage](ServiceMessage.md) entries by category, so a caller can distinguish business validation failures from infrastructure failures without inspecting exception details itself ([BR-APP-009](../../business-rules.md#br-app-009-service-responses-succeed-until-declared-otherwise-exceptions-are-environmental)).

## Purpose
- Accumulates messages of four categories (`Error`, `Warning`, `Information`, `Environment`) in a single ordered collection, exposing filtered views for each.
- Converts a caught `Exception` (and its inner-exception chain) into `Environment`-category messages via `ProcessException`, so infrastructure failures are reported consistently with business messages.
- Leaves the overall `Result` flag under caller control — this type never sets it to `False` itself, even when error messages are present ([BR-APP-009](../../business-rules.md#br-app-009-service-responses-succeed-until-declared-otherwise-exceptions-are-environmental)).

## Context
- Namespace: `SAIF.Application`
- Assembly/package: `SAIF.Application` (embedded, ProjectReference)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `Result` | `Public Boolean` field, default `True` | Overall success flag; the caller must explicitly set it to `False` on failure ([BR-APP-009](../../business-rules.md#br-app-009-service-responses-succeed-until-declared-otherwise-exceptions-are-environmental)). |
| `RequestID` | `Public String` field, default `String.Empty` | Caller-supplied correlation id echoed back with the response. |
| `Messages` | `Public ReadOnly Property As IEnumerable(Of ServiceMessage)` | All accumulated messages in insertion order, across all categories. |
| `Errors` | `Public ReadOnly Property As IEnumerable(Of ServiceMessage)` | `Messages` filtered to `ServiceMessageType.Error` — business validation failures. |
| `Warnings` | `Public ReadOnly Property As IEnumerable(Of ServiceMessage)` | `Messages` filtered to `ServiceMessageType.Warning`. |
| `InformationalMessages` | `Public ReadOnly Property As IEnumerable(Of ServiceMessage)` | `Messages` filtered to `ServiceMessageType.Information`. |
| `EnvironmentalErrors` | `Public ReadOnly Property As IEnumerable(Of ServiceMessage)` | `Messages` filtered to `ServiceMessageType.Environment` — infrastructure/exception-derived failures. |
| `ProcessException` | `Public Sub (ex As Exception)` | Converts an exception and its inner-exception chain into `Environment`-category messages keyed by each exception's type name ([BR-APP-009](../../business-rules.md#br-app-009-service-responses-succeed-until-declared-otherwise-exceptions-are-environmental)). |
| `AddErrorMessage` | `Public Sub (inMessage As String, Optional inKey As String = "")` | Appends a business validation failure to `Messages` as an `Error`-category `ServiceMessage`. |
| `AddWarningMessage` | `Public Sub (inMessage As String, Optional inKey As String = "")` | Appends a `Warning`-category `ServiceMessage`. |
| `AddInformationMessage` | `Public Sub (inMessage As String, Optional inKey As String = "")` | Appends an `Information`-category `ServiceMessage`. |
| `AddEnvironmentMessage` | `Public Sub (inMessage As String, Optional inKey As String = "")` | Appends an `Environment`-category `ServiceMessage`, the same category `ProcessException` uses. |

## Behavioral notes
- `ProcessException` walks the inner-exception chain, but a defect re-assigns the loop variable to `ex.InnerException` (the outer exception) instead of the current `LocalEX.InnerException`; any exception with a non-`Nothing` inner exception causes an infinite loop that appends the same message repeatedly.**
- `Result` is never modified by this class — it remains `True` unless the caller explicitly sets it to `False`, even after `AddErrorMessage` or `ProcessException` calls ([BR-APP-009](../../business-rules.md#br-app-009-service-responses-succeed-until-declared-otherwise-exceptions-are-environmental)).

## Constraints and usage notes
- Callers must inspect `Errors` / `EnvironmentalErrors` themselves and set `Result = False` accordingly; this type does not derive `Result` automatically from message content.
- Given the `ProcessException` infinite-loop defect, callers passing exceptions with a populated `InnerException` chain should verify behavior before relying on this method in production paths.**

> **Note:** Statements marked with `*` were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with `**` could not be confirmed; treat as unknown until verified.

## Sources
- `SAIF.Application/Service Based/ServiceResponse.vb`
- `SAIF.Application/Service Based/ServiceMessage.vb`
